//
//  XMGNavigationController.m
//  01 baisi
//
//  Created by 檀志文 on 16/2/13.
//  Copyright © 2016年 ios檀志文. All rights reserved.
//

#import "XMGNavigationController.h"

@implementation XMGNavigationController

//当第一次使用这个类时候调用一次

+(void) initialize{
    UINavigationBar *bar = [UINavigationBar appearance];
    [bar setBackgroundImage:[UIImage imageNamed:@"navigationbarBackgroundWhite"] forBarMetrics:UIBarMetricsDefault];
}

-(void)viewDidLoad{
    [super viewDidLoad];
    
}

//控制器一旦push 进去，控制器的view就会创建，然后就会调用viewDidLoad方法。就会 调用self.navigationItem.leftBarButtonItem 重新设置

-(void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated{
    
        if(self.childViewControllers.count > 0){
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        [btn setTitle:@"返回" forState:UIControlStateNormal];
        [btn setImage:[UIImage imageNamed:@"navigationButtonReturn"] forState:UIControlStateNormal];
        btn.size = CGSizeMake(70, 30);
        btn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        
        btn.contentEdgeInsets = UIEdgeInsetsMake(0, -10, 0, 0);
        
        [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        
        [btn setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted];
        
        [btn addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
        
        // push 隐藏导航条的效果
        
        viewController.hidesBottomBarWhenPushed = YES;
}
        // 当调用这个方法，才是真正将控制器放到数组中去
    [super pushViewController:viewController animated:YES];
}

-(void)back{
    [self popViewControllerAnimated:YES];
}
@end
